package ModeLayer;
import java.util.ArrayList;

/**
 * Write a description of class ContainerForest here.
 * 
 * @author (Kis Boisen Hansen) 
 * @version (2014.01.04)
 */
public class ContainerForest
{
   
    private static ContainerForest instance;
    private ArrayList<Forest> forestList;
    /**
     * Constructor for objects of class ContainerForest
     */
    private ContainerForest()
    {
        // initialise instance variables
       forestList = new ArrayList<Forest>();
    }

    //Singelton
    public static ContainerForest getInstance() 
    {
        if(instance == null)
        {
            instance = new ContainerForest();
        }
        return instance;
       
    }
    public void addForest(Forest newForest)
    {
        forestList.add(newForest);
    }
    public Forest findForest(String name)
    {
        int index =0;
        boolean found = false;
        while(index < forestList.size() && !found)
        {
            Forest forestObj = forestList.get(index);
            if(forestObj.getName().equals(name))
            {
                found = true;
            }
            else{
                index ++;
            }
                    
        }
        if(found)
        {
            return forestList.get(index);
        }
        else{
            return null;
        }
    
    }
}
